home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.12 Dec 96 / Async I⁄O Code / Sources / LabMaker.h < prev    next >
Encoding:
Text File  |  1995-11-07  |  5.1 KB  |  139 lines  |  [TEXT/CWIE]

  1. // File: LabMaker.h
  2.  
  3. enum {
  4.     kMaxLabNameLength    = 16,    // Longest possible lab name
  5.     kMaxFileNameLength    = 32,    // Longest possible file or path name
  6.     kFullPathLength        = 128,    // 4 * kMaxFileNameLength
  7.     kMaxLabs            = 32,    // How many lab files can be open at a time
  8.     kMaxLineLength        = 256,    // How long of a line will we process
  9.     kStackSize            = 16,    // How many pushes will we accept
  10.     kMaxFileTypes        = 16,    // How many file suffixes will we accept
  11.     kMaxCommandLength    = 16,    // Commands are no longer than 16 characters
  12.     kMaxCommentTypes    = 4,    // We'll accept up to 4 styles of comments
  13.     kMaxCommentLength    = 4        // Maximum numbers of characters in a comment delimeter
  14. };
  15.  
  16. enum {
  17.     // return results for FindLab and FindSuffix
  18.     kAllLabs      = -2,
  19.     kLabNotFound = -1,
  20.     kSuffixNotFound = -1
  21. };
  22.  
  23. enum {
  24.     // Options for "Pop"
  25.     kReplaceLabs = 0,
  26.     kMergeLabs     = 1
  27. };
  28.  
  29. enum {
  30.     // Options in the command table
  31.     kNoParams = 0,                    // Don't bother to extract parameters from the string
  32.     kPassComment,                    // Pass the whole comment to the command (e.g. /* $comment */)
  33.     kPassParams,                    // Pass only the parameter list to the command
  34.     kPassBuffer                        // Pass the whole line to the command
  35. };
  36.     
  37. struct CommentInfo {
  38.     char    commentStart[kMaxCommentLength];
  39.     char    commentEnd[kMaxCommentLength];
  40.     short    columnOneOnly;            // True if this comment delimeter must begin in column 1
  41. };
  42.  
  43. typedef struct CommentInfo CommentInfo;
  44.  
  45. struct FileOptions {
  46.     char        suffix[kMaxFileNameLength];
  47.     short        numCommentTypes;
  48.     char        commandChar;
  49.     CommentInfo    commentDelimiters[kMaxCommentTypes];
  50. };
  51.  
  52. typedef struct FileOptions FileOptions;
  53.  
  54. struct LabInfo {
  55.     short    isActive;
  56.     char    labName[kMaxLabNameLength];
  57.     char    directoryName[kMaxFileNameLength];
  58.     FILE*    file;
  59. };
  60.  
  61. typedef struct LabInfo LabInfo;
  62.  
  63. typedef void (*Command)(char *buffer, short paramStart, short paramEnd, char* filename);
  64.  
  65. struct CommandEntry {
  66.     char            commandName[kMaxCommandLength];
  67.     int                uniqueChars;
  68.     Command            theCommand;
  69.     unsigned int    options;
  70. };
  71.  
  72. typedef struct CommandEntry CommandEntry;
  73.  
  74. struct CurrentState {
  75.     FileOptions        *currFileOptions;
  76.     char            *currFilename;
  77.     short            numLabs;
  78.     LabInfo            labs[kMaxLabs];
  79.     short            isInclude;
  80.     short            skipBlanks;                    // Should we skip blank lines?
  81.     char            buffer[kMaxLineLength];        // A copy of the current buffer, for error
  82.                                                 // reporting purposes
  83. };
  84.  
  85. typedef struct CurrentState CurrentState;
  86.  
  87.  
  88. // --- Prototypes
  89.  
  90. void Error(char* message, char *buffer, short index, char* fileName);
  91. void Warning(char* message, char *buffer, short index, char* fileName);
  92. int GetOrMakeDirectory(char *path, short isFullPath);
  93. FILE* GetOrMakeFile(char* fileName, char *path, short isFullPath);
  94. int CopyFile(char* sourceFileName, char *sourcePath, char* copyPath, short isFullPath);
  95.  
  96. static char *MakeLower(char* buffer);
  97.  
  98. int ProcessUserFile(char *filename);
  99. void ProcessLine(char *buffer, int *inComment, char* filename);
  100. void RemoveComment(char *buffer, short *index, short startOfComment);
  101. CommandEntry *FindCommand(char *possibleCommand);
  102. short FindLab(char* labName);
  103. short FindSuffix(char* suffix);
  104. char *GetKeyword(char* keyword, char* buffer, short *index, char* result);
  105. char *GetNextSubstring(char* buffer, short *index, char *result, short allowQuotes);
  106. char *GetLabName(char* buffer, short *index, char *result);
  107. char *GetFileName(char* buffer, short *index, char *result);
  108. char *GetDirectoryName(char* buffer, short *index, char *result);
  109. char *FindCommentStart(char *buffer, short *index, short *startOffset, short *commentKind);
  110. char *FindCommentEnd(char *buffer, short *index, short *endOffset, short commentKind);
  111. char *SkipWhitespace(char *buffer, short *index);
  112. void DistributeLine(char *buffer);
  113. void GetFileOptions(char *filename);
  114. void OpenLab(short labID);
  115. void CloseLab(short labID);
  116. void CloseAllLabs(void);
  117. void Push(void);
  118. void Pop(short options);
  119. void CopyOrSkip(char *buffer, short paramStart, short paramEnd, char* filename, short activate);
  120. void ClearFileOption(FileOptions *oneOption);
  121.  
  122. void DoInsert(char *buffer, short paramStart, short paramEnd, char* filename);
  123. void DoComment(char *buffer, short paramStart, short paramEnd, char* filename);
  124. void DoCreate(char *buffer, short paramStart, short paramEnd, char* filename);
  125. void DoInclude(char *buffer, short paramStart, short paramEnd, char* filename);
  126. void DoCopy(char *buffer, short paramStart, short paramEnd, char* filename);
  127. void DoSkip(char *buffer, short paramStart, short paramEnd, char* filename);
  128. void DoInsert(char *buffer, short paramStart, short paramEnd, char* filename);
  129. void DoPush(char *buffer, short paramStart, short paramEnd, char* filename);
  130. void DoPop(char *buffer, short paramStart, short paramEnd, char* filename);
  131. void DoSuffix(char *buffer, short paramStart, short paramEnd, char* filename);
  132. void DoDelimiter(char *buffer, short paramStart, short paramEnd, char* filename);
  133. void DoReset(char *buffer, short paramStart, short paramEnd, char* filename);
  134. void DoOnly(char *buffer, short paramStart, short paramEnd, char* filename);
  135. void DoNot(char *buffer, short paramStart, short paramEnd, char* filename);
  136. void DoEndSuffix(char *buffer, short paramStart, short paramEnd, char* filename);
  137. void DoSkipBlanks(char *buffer, short paramStart, short paramEnd, char* filename);
  138.  
  139.